home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 35 / Amiga Format AFCD35 (Issue 119, Jan 1999).iso / -in_the_mag- / reader_requests / trackloader / trackloader.asm < prev   
Assembly Source File  |  1998-11-06  |  11KB  |  400 lines

  1. ****************************************************************************
  2. *                                                                          *
  3. *              This Trackloader was coded by Patrik Lundquist              *
  4. *                                                                          *
  5. *                               Version 1.0                                *
  6. *                                                                          *
  7. *                Copyright (C) 1991-93 by SnurgelGmurf Soft                *
  8. *                                                                          *
  9. *                                                                          *
  10. * I coded this loader back in 1991 and fixed a bug in May `93.             *
  11. * The reason why I release this loader is that I'm tired of all            *
  12. * loaders that won't work on accelerated Amigas.                           *
  13. *                                                                          *
  14. * The loader accepts blocks in the range of 0-1803 (cylinders 0-81).       *
  15. * I wouldn't recommend using cylinders 80-81 as it's not standard.         *
  16. * No error checking is done. It's quite easy to implement checksum check.  *
  17. * You can have this loader running outside your interrupts and             *
  18. * don't need to worry about it. You must have $dff000 in a5 when you       *
  19. * jump to Loader. Registers d0-7/a0-1 are modified in Loader.              *
  20. *                                                                          *
  21. * You may use this source partly or in whole in any way you want EXCEPT    *
  22. * for destructive purposes like viruses.                                   *
  23. * I would appreciate credits if you use it.                                *
  24. *                                                                          *
  25. * This sourcecode may not be distributed for a profit.                     *
  26. *                                                                          *
  27. * This sourcecode is provided "AS IS" without warranty of any kind, either *
  28. * expressed or implied. By using this source you agree to accept the       *
  29. * entire risk as to the quality and performance of the program. I can NOT  *
  30. * be held liable for any damaged caused by this sourcecode.                *
  31. *                                                                          *
  32. *                                                                          *
  33. * You can reach me here:                                                   *
  34. *                                                                          *
  35. * Internet:     pi92plu@pt.hk-r.se                                         *
  36. *                                                                          *
  37. * IRC:          Look for 'PatrikL' on #amiga channel.                      *
  38. *                                                                          *
  39. ****************************************************************************
  40.  
  41.  
  42.         Section    Trackloader,Code
  43.         Opt    c+,o+
  44.  
  45.  
  46. SyncWord    Equ    $4489            Standard sync value.
  47. AdkCon        Equ    $9500
  48.  
  49.  
  50.         Bsr.s    Init            Setup hardware registers.
  51.  
  52.         Move.l    #880,d0            Start block, 0-1803.
  53.         Moveq    #88,d1            Number of blocks to read.
  54.         Lea    DestBuffer,a0        Destination address.
  55.         Bsr    Loader
  56.  
  57.         Moveq    #0,d0            Start block, 0-1803.
  58.         Moveq    #88,d1            Number of blocks to read.
  59.         Lea    DestBuffer,a0        Destination address.
  60.         Bsr    Loader
  61.  
  62.         Move.l    #1600,d0        Start block, 0-1803.
  63.         Moveq    #88,d1            Number of blocks to read.
  64.         Lea    DestBuffer,a0        Destination address.
  65.         Bsr    Loader
  66.  
  67.         Bsr    Exit            Restore hardware registers.
  68.         Rts
  69.  
  70. *­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*
  71.  
  72. Init        Lea    $dff000,a5        customchip-base into a5
  73.  
  74.         Move.b    $bfde00,CIA_B        Save tmr A Control reg
  75.         Move.w    $2(a5),OldDMA        save dma channels
  76.         Bset    #7,OldDMA
  77.         Move.b    $10(a5),OldADKCON    save old ADKCON
  78.         Bset    #7,OldADKCON
  79.         Move.w    $1c(a5),oldintena    save old interrupt enable
  80.         Bset    #7,oldintena
  81.         Move.w    $1e(a5),oldintreq    save old interrupt request
  82.         Bset    #7,oldintreq
  83.  
  84.         Move.w    #$7fff,d1
  85.         Move.w    d1,$9a(a5)        kill all interrupts
  86.         Move.w    d1,$9c(a5)
  87.         Move.w    d1,$96(a5)
  88.  
  89.         Move.w    #SyncWord,$7e(a5)    DSKSYNC
  90.         Move.w    #AdkCon,$9e(a5)        ADKCON
  91.         Move.w    #$8200,$96(a5)
  92.         Move.b    #%01001100,$bfde00    Stop, one-shot mode.
  93.  
  94.         Bsr.s    SelDF0MotOn
  95.         Bsr    GoToTrack00
  96.         Bsr    SelDF0MotOff
  97.         Rts
  98.  
  99. *­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­*
  100.  
  101. Exit        Move.w    OldDMA(pc),$96(a5)    Restore old dma.
  102.         Move.b    CIA_B(pc),$bfde00    Restore tmr A Control reg.
  103.         Move.b    OldADKCON(pc),$9e(a5)
  104.         Move.w    oldintena(pc),$9a(a5)    Restore old interrupt enable.
  105.         Move.w    oldintreq(pc),$9c(a5)
  106.         Moveq    #0,d0
  107.         Rts
  108.  
  109. *===========================================================================*
  110.  
  111. SelDF0MotOn    Or.b    #$78,$bfd100    Set bits 3,4,5 and 6,
  112.                 ;    deselect all drives.
  113.         Bclr    #7,$bfd100    Switch on motor.
  114.         Nop
  115.         Nop
  116.         Bclr    #3,$bfd100    Clear bit 3, DF0
  117.         Rts
  118.  
  119. *­---------------------------------------------­*
  120.  
  121.     *    Control routine.
  122.  
  123.     *    Start block -> d0
  124.     *    Number of blocks -> d1
  125.     *    Destination address -> a0
  126.  
  127. Loader        Tst.l    d1
  128.         Beq    ExitLR
  129.         Bmi    ExitLR
  130.         Tst.l    d0
  131.         Bmi    ExitLR            Boundary check.
  132.         Move.l    d1,d2
  133.         Add.l    d0,d2
  134.         Cmp.l    #1804,d2
  135.         Bgt    ExitLR
  136.  
  137.         Bsr.s    SelDF0MotOn
  138.         Divu    #11,d0
  139.         Move.b    d0,StartTrack
  140.         Move.l    d0,d2
  141.         Swap     d2
  142.         Move.b    d2,StartSector
  143.         Add.b    d2,d1
  144.         Divu    #11,d1
  145.         Move.l    d1,d2
  146.         Swap     d2
  147.         Tst.b    d2
  148.         Bne.s    EqualTrack
  149.         Subq.b    #1,d1
  150.         Move.b    #11,d2
  151. EqualTrack    Move.b    d1,Tracks
  152.         Move.b    d2,EndSector
  153.  
  154.         Move.b    d0,d1            Start-track in d0.
  155.         Move.b    Position(pc),d2
  156.         Lsr.b    #1,d1
  157.         Lsr.b    #1,d2
  158.         Cmp.b    d1,d2
  159.         Beq.s    RightCyl        No need to move head.
  160.         Blt.s    MoveHeadIn
  161.         Sub.b    d1,d2            Moving head outwards.
  162.         Bsr    MoveOutwards
  163.         Subq.b    #1,d2
  164.         Beq.s    RightCyl
  165.         Subq.b    #1,d2
  166.         Ext.w    d2
  167. .MoveHeadOut    Bsr    MoveHead
  168.         Dbra    d2,.MoveHeadOut
  169.         Bra.s    RightCyl
  170. MoveHeadIn    Sub.b    d2,d1            Moving head inwards.
  171.         Bsr    MoveInwards
  172.         Subq.b    #1,d1
  173.         Beq.s    RightCyl
  174.         Subq.b    #1,d1
  175.         Ext.w    d1
  176. .MoveHeadIn    Bsr    MoveHead
  177.         Dbra    d1,.MoveHeadIn
  178. RightCyl    Btst    #0,StartTrack        Time to choose side.
  179.         Beq.s    .LowerIt
  180.         Btst    #2,$bfd100
  181.         Beq.s    RightTrack
  182.         Bsr    Upper
  183.         Bra.s    RightTrack
  184. .LowerIt    Btst    #2,$bfd100
  185.         Bne.s    RightTrack
  186.         Bsr    Lower
  187. RightTrack    Move.b    StartSector(pc),d3    And now, the reading begins.
  188.         Move.b    Tracks(pc),d2
  189.         Beq.s    LastTrack
  190.         Moveq    #11,d4
  191.         Bsr.s    Read
  192. NextTrack    Moveq    #0,d3
  193.         Btst    #2,$bfd100
  194.         Bne.s    NextSide
  195.         Bsr    Lower
  196.         Btst    #1,$bfd100
  197.         Bne.s    .FirstMoveIn
  198.         Bsr    MoveHead
  199.         Bra.s    NextRead
  200. .FirstMoveIn    Bsr    MoveInwards
  201.         Bra.s    NextRead
  202. NextSide    Bsr    Upper
  203. NextRead    Subq.b    #1,d2
  204.         Beq.s    LastTrack
  205.         Bsr.s    Read
  206.         Bra.s    NextTrack
  207. LastTrack    Move.b    EndSector(pc),d4
  208.         Bsr.s    Read
  209.         Bsr.s    SelDF0MotOff
  210. ExitLR        Rts
  211.  
  212. *­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­-­*
  213.  
  214. SelDF0MotOff    Or.b    #$f8,$bfd100    Set bits 3,4,5,6 and 7,
  215.         Nop            deselects all drives, motor off.
  216.         Nop
  217.         Bclr    #3,$bfd100    Clear bit 3, select drive 0.
  218.         Rts
  219.  
  220. *­---------------------------------------------­*
  221.  
  222. Read        Btst    #5,$bfe001        Await Disk ready.
  223.         Bne.s    Read
  224.         Move.b    #$91,$bfd400        Timer A low.
  225.         Move.b    #$29,$bfd500        Timer A hi, and starts timer.
  226.         Bsr    Timer
  227.         Move.w    #2,$9c(a5)        Clear Disk Intrequest.
  228.         Move.l    #TrackBuffer,$20(a5)    DSKPT, MFM-buffer.
  229.         Move.w    #$8010,$96(a5)        Disk DMA on.
  230.         Move.w    #$4000,$24(a5)        dsklen
  231.         Move.w    #$9900,$24(a5)        dsklen, read lenght.
  232.         Move.w    #$9900,$24(a5)        dsklen
  233. .DMAwait    Btst    #1,$1f(a5)        DMA transfer done when high.
  234.         Beq.s    .DMAwait
  235.         Move.w    #$4000,$24(a5)
  236.         Move.w    #$0010,$96(a5)        Disk DMA off.
  237.  
  238. *­---------------------------------------------­*
  239.     *    Destination address -> a0
  240.     *    Start sector -> d3
  241.     *    End sector -> d4
  242.  
  243. Decode        Move.w    #SyncWord,d5        Sync-word.
  244.         Move.l    #$55555555,d7        %010101...
  245.  
  246. FindSector    Lea    TrackBuffer,a1        Move Buffer-address.
  247. SyncSearch    Cmp.w    (a1)+,d5        Check for Sync-word.
  248.         Bne.s    SyncSearch
  249.         Cmp.w    (a1),d5            Another Sync-word?
  250.         Beq.s    SyncSearch
  251.         Move.l    (a1),d0
  252.         Move.l    4(a1),d1
  253.         And.l    d7,d0
  254.         Asl.l    #1,d0
  255.         And.l    d7,d1
  256.         Or.l    d1,d0
  257.         Ror.l    #8,d0
  258.         Cmp.b    d3,d0            Correct sector?
  259.         Beq.s    SectorOK
  260.         Lea    $43E(a1),a1        Add to next sector.
  261.         Bra.s    SyncSearch
  262.  
  263. SectorOK    Addq.b    #1,d3
  264.         Lea    $38(a1),a1        Skip InfoBytes.
  265.         Moveq    #$7f,d6
  266. DeCodeLoop    Move.l    $200(a1),d1
  267.         Move.l    (a1)+,d0
  268.         And.l    d7,d0
  269.         Asl.l    #1,d0
  270.         And.l    d7,d1
  271.         Or.l    d1,d0
  272.         Move.l    d0,(a0)+        Move to Load Address.
  273.         Dbra    d6,DeCodeLoop
  274.         Cmp.b    d4,d3
  275.         Bne.s    FindSector
  276.         Rts
  277.  
  278. *­---------------------------------------------­*
  279.  
  280. GoToTrack00    Btst    #4,$bfe001    Track 00 when low.
  281.         Beq.s    Pos00
  282.         Bsr.s    MoveOutwards
  283. TowardsTrack00    Btst    #4,$bfe001    Track 00 when low.
  284.         Beq.s    Pos00
  285.         Bclr    #0,$bfd100    Move head.
  286.         Nop
  287.         Nop
  288.         Bset    #0,$bfd100    Prepare to move head.
  289.         Move.b    #$69,$bfd400    Timer A low.
  290.         Move.b    #$0e,$bfd500    Timer A hi, and starts timer.
  291.         Bsr.s    Timer        5.2ms
  292.         Bra.s    TowardsTrack00
  293. Pos00        Clr.b    Position
  294.         Rts
  295.  
  296. *­---------------------------------------------­*
  297.  
  298. Upper        Bclr    #2,$bfd100    Upper side.
  299.         Move.b    #$47,$bfd400    Timer A low.
  300.         Move.b    #$00,$bfd500    Timer A hi, and starts timer.
  301.         Bra.s    Timer        100µs
  302.  
  303. *­---------------------------------------------­*
  304.  
  305. Lower        Bset    #2,$bfd100    Lower side.
  306.         Move.b    #$47,$bfd400    Timer A low.
  307.         Move.b    #$00,$bfd500    Timer A hi, and starts timer.
  308.         Bra.s    Timer        100µs
  309.  
  310. *­---------------------------------------------­*
  311.  
  312. MoveOutwards    Bset    #1,$bfd100    Head direction outward.
  313.         Bclr    #0,$bfd100    Move head.
  314.         Nop
  315.         Nop
  316.         Bset    #0,$bfd100    Prepare to move head.
  317.         Move.b    #$e1,$bfd400    Timer A low.
  318.         Move.b    #$31,$bfd500    Timer A hi, and starts timer.
  319.         Move.b    #-2,Direction
  320.         Add.b    #-2,Position    18ms
  321.  
  322. *­---------------------------------------------­*
  323.  
  324. Timer        Move.b    $bfdd00,d0    Await Timer ready.
  325.         Btst    #0,d0
  326.         Beq.s    Timer
  327. Rts        Rts
  328.  
  329. *­---------------------------------------------­*
  330.  
  331. MoveInwards    And.b    #$fc,$bfd100    Clear bits 0 and 1,
  332.         Nop    which results in diskdirec=inwards, head moved.
  333.         Nop
  334.         Bset    #0,$bfd100    Prepare to move head.
  335.         Move.b    #$e1,$bfd400    Timer A low.
  336.         Move.b    #$31,$bfd500    Timer A hi, and starts timer.
  337.         Move.b    #2,Direction
  338.         Addq.b    #2,Position
  339.         Bra.s    Timer        18ms
  340.  
  341. *­---------------------------------------------­*
  342.  
  343. MoveHead    Bclr    #0,$bfd100    Move head.
  344.         Nop
  345.         Nop
  346.         Bset    #0,$bfd100    Prepare to move head.
  347.         Move.b    #$50,$bfd400    Timer A low.
  348.         Move.b    #$08,$bfd500    Timer A hi, and starts timer.
  349.         Move.b    Direction(pc),d0
  350.         Add.b    d0,Position
  351.         Bra.s    Timer        3ms
  352.  
  353. *­---------------------------------------------­*
  354.  
  355. oldintena    Ds.w    1
  356. oldintreq    Ds.w    1
  357. OldDMA        Ds.w    1
  358. CIA_B        Ds.b    1
  359. OldADKCON    Ds.b    1
  360.  
  361. Position    Ds.b    1
  362. Direction    Ds.b    1
  363. StartTrack    Ds.b    1
  364. StartSector    Ds.b    1
  365. Tracks        Ds.b    1
  366. EndSector    Ds.b    1
  367.  
  368. *­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*
  369.  
  370.     Section Track,BSS_C
  371.  
  372. TrackBuffer    Ds.w    $1900        Room for one MFM-track.
  373.  
  374. *­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*
  375.  
  376.     Section    Destination,BSS
  377.  
  378. DestBuffer    Ds.b    512*88        This is for test purpose.
  379.  
  380. *­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*
  381.  
  382.         End
  383.  
  384. *­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*
  385. Operation:                WaitTime:    Timervalue:
  386. ­­­­­­­­­                ­­­­­­­­    ­­­­­­­­­­
  387.  Motor on                500ms, DSKRDY    $56982
  388.  Diskside stable before reading        100µs        $47
  389.  Diskside stable before writing        100µs        $47
  390.  Diskside stable after writing        1.3ms        $39A
  391.  Diskstep                3ms        $850
  392.  Reverse diskstep            18ms        $31E1
  393.  Settle time                15ms        $2991
  394.  Track 00 signal low after step        2.2ms        $619
  395.  Track 00 signal hi after step        1µs        $1
  396.  Step after drive select        1µs        $1
  397.  Direction select before step        1µs        $1
  398.  Direction select after step        1µs        $1
  399.  Keep low signal            1µs        $1
  400.